package 一些基础的数据结构;

import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;

import java.util.HashMap;
import java.util.TreeMap;

public class HashMapAndSortedMap {

    public static class Zuo{
        public int value;

        public Zuo(int value) {
            this.value = value;
        }
    }

    public static void main(String[] args) {

        // 按引用传递
        Integer a = 199;
        Integer b = 199;
        System.out.println(a == b);

        // 按值传递 (在哈希表中 原生数据类型按值传递)
        HashMap<Integer, String> map1 = new HashMap<>();
        map1.put(a, "我是3");
        System.out.println(map1.containsKey(b));

        // 不是原生，按引用传递
        Zuo z1 = new Zuo(1);
        Zuo z2 = new Zuo(1);
        HashMap<Zuo, String> map2 = new HashMap<>();
        map2.put(z1,"我是z1");
        System.out.println(map2.containsKey(z2));



        // TreeMap 有序表：接口名
        // 红黑树、AVL 、sb数、跳表
        // logN
        TreeMap<Integer,String> treeMap = new TreeMap<>();
        treeMap.put(1,"我是1");
        treeMap.put(2,"我是2");
        treeMap.put(3,"我是3");
        System.out.println("新增功能-------------");
        System.out.println(treeMap.firstKey());
        System.out.println(treeMap.lastKey());
        System.out.println(treeMap.floorKey(2));  // <=2
        System.out.println(treeMap.ceilingKey(2));  // >=2


        System.out.println("==============================");
        HashMap<Integer,Integer> hashMap1 = new HashMap<>();
        hashMap1.put(1,1);
        hashMap1.put(2,144);
        HashMap<Integer,Integer> hashMap2 = new HashMap<>();
        hashMap2.put(1,1);
        hashMap2.put(2,144);
        System.out.println(hashMap1.get(1) == hashMap2.get(1)); // 值传递
        System.out.println(hashMap1.get(2) == hashMap2.get(2)); // 引用传递

    }





}
